﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using CommDll;

namespace HospitalMedicineTraceability
{
    /// <summary>
    /// ClassName:frmCodeCollect_WarehouseStockIn1
    /// Version:1.0
    /// Date:2022-10-21
    /// Author:seanouyang
    /// </summary>
    /// <remarks>
    /// 本类是一WinForm 窗体,本窗体主要为部门设置
    /// </remarks>
    public partial class frmDeptDetail : DevComponents.DotNetBar.OfficeForm
    {
        public int m_nOperateKind = 0;//0:查看 1:新增 2:修改 
        public Boolean m_bIsRefresh = false;    //是否需刷新
        public SystemDept m_systemDept = new SystemDept();

        public frmDeptDetail()
        {
            InitializeComponent();
        }

        #region 01 自定义方法
        /// <summary>
        /// 数据初始化
        /// </summary>
        private void _init()
        {
            txtCode.Text = m_systemDept.m_strCode;
            txtName.Text = m_systemDept.m_strName;
            txtCode.Focus();
            txtCode.ReadOnly = false;
            txtName.ReadOnly = false;
            cbIsNew.Visible = m_systemDept.m_nOperate == 1;
        }

       
        /// <summary>
        /// 保存扫码信息
        /// </summary>
        /// <param name="strCode"></param>
        /// <param name="bIsNew"></param>
        private Boolean _saveCode()
        {
            Boolean bResult = false;
            m_systemDept.m_strCode = txtCode.Text.Trim();
            m_systemDept.m_strName = txtName.Text.Trim();
            if (m_systemDept.m_strCode.Length < 1)
            {
                CommFun._messageBoxShow("编号不能为空!");
                return false;
            }
            if (m_systemDept.m_strName.Length < 1)
            {
                CommFun._messageBoxShow("名称不能为空!");
                return false;
            }            
            // 保存数据
            if (!m_systemDept._checkName())
            {
                return false;
            }

            if (m_systemDept._saveInfo() < 1)
            {
                CommFun._messageBoxShow("数据保存失败");
            }
            else
            {
                m_bIsRefresh = true;
                CommFun._messageBoxShow("数据保存成功");
                if (cbIsNew.Checked)    // 继续新增
                {
                    m_systemDept._init();
                    _init();
                }
                else
                {
                    this.DialogResult = DialogResult.OK;
                }                
            }
            return bResult;
        }
        
        #endregion

        #region  02 窗体相关事件方法
        private void frmConfig_Load(object sender, EventArgs e)
        {
            // 初始化
            _init();
            cbIsNew.Checked = m_systemDept.m_nOperate == 1;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            _saveCode();
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}
